package com.fjk.auth.controller;

import com.fjk.auth.domain.LoginUser;
import com.fjk.module.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private RedisTemplate redisTemplate;

    @PostMapping("/login")
    public String login(@RequestBody LoginUser loginUser){
        /* TODO 校验账户密码 */
        /* 生成token */
        String token = JwtUtil.getToken(loginUser.getUserName());
        /* token存入redis */
        redisTemplate.opsForValue().set(token, loginUser.toString(), 60, TimeUnit.MINUTES);
        return token;
    }
}
